VERSION 5.00
Begin VB.Form Form1 
   Caption         =   "PPLZ Lib Example"
   ClientHeight    =   1485
   ClientLeft      =   60
   ClientTop       =   450
   ClientWidth     =   3885
   LinkTopic       =   "Form1"
   ScaleHeight     =   1485
   ScaleWidth      =   3885
   StartUpPosition =   2  'CenterScreen
   Begin VB.CommandButton Command1 
      Caption         =   "Print Label"
      Height          =   500
      Left            =   900
      TabIndex        =   0
      Top             =   400
      Width           =   2100
   End
End
Attribute VB_Name = "Form1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
    Private Type SECURITY_ATTRIBUTES
        nLength As Long
        lpSecurityDescriptor As Long
        bInheritHandle As Long
    End Type

    Private Declare Function CreateDirectory Lib "kernel32" Alias "CreateDirectoryA" _
            (ByVal lpPathName As String, lpSecurityAttributes As SECURITY_ATTRIBUTES) As Long
    Private Declare Sub RtlMoveMemory Lib "kernel32" (ByVal lpvDest As String, _
            ByVal lpvSource As Long, ByVal cbCopy As Long)
            
    Const IMAGE_BITMAP = 0
    Const LR_LOADFROMFILE = &H10
    Private Declare Function LoadImage Lib "user32" Alias "LoadImageA" (ByVal hInst As Long, _
            ByVal lpsz As String, ByVal un1 As Long, ByVal n1 As Long, ByVal n2 As Long, _
            ByVal un2 As Long) As Long
    Private Declare Function DeleteObject Lib "Gdi32" (ByVal ho As Long) As Long
    Const szSavePath As String = "C:\Argox"
    Const szSaveFile As String = "C:\Argox\PPLZ_Example.Prn"
    Const sznop1 As String = "nop_front" + vbCrLf
    Const sznop2 As String = "nop_middle" + vbCrLf
    Private Declare Function Z_Bar2d_Maxi Lib "WINPPLZ.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal nMode As Long, ByVal nSymbol As Long, ByVal nTotal As Long, ByVal nClass As Long, _
            ByVal nCountry As Long, ByVal cZipCode1 As String, ByVal cZipCode2 As String, _
            ByVal data As String, ByVal increase As Long) As Long
    Private Declare Function Z_Bar2d_PDF417 Lib "WINPPLZ.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal o As Long, ByVal h As Long, ByVal s As Long, ByVal c As Long, ByVal r As Long, _
            ByVal t As Long, ByVal narrow As Long, ByVal data As String, ByVal increase As Long) As Long
    Private Declare Function Z_Bar2d_DataMatrix Lib "WINPPLZ.DLL" (ByVal x As Integer, ByVal y As Integer, _
            ByVal o As Integer, ByVal h As Integer, ByVal c As Integer, ByVal r As Integer, _
            ByVal data As String, ByVal increase As Integer) As Integer
    Private Declare Sub Z_ClosePrn Lib "WINPPLZ.DLL" ()
    Private Declare Function Z_CreatePrn Lib "WINPPLZ.DLL" (ByVal selection As Long, _
            ByVal filename As String) As Long
    Private Declare Function Z_Set_FlashMemory Lib "WINPPLZ.DLL" (ByVal Status As Long) As Long
    Private Declare Sub Z_Set_Format_New Lib "WINPPLZ.DLL" (ByVal FormatName As String)
    Private Declare Function Z_Del_Format Lib "WINPPLZ.DLL" (ByVal nMem As Long, _
            ByVal formname As String) As Long
    Private Declare Function Z_Del_Graphic Lib "WINPPLZ.DLL" (ByVal memory As Long, _
            ByVal graphicname As String) As Long
    Private Declare Function Z_Draw_Box Lib "WINPPLZ.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal width As Long, ByVal height As Long, ByVal thickness As Long) As Long
    Private Declare Function Z_Draw_Line Lib "WINPPLZ.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal width As Long, ByVal height As Long) As Long
    Private Declare Function Z_Get_DLL_Version Lib "WINPPLZ.DLL" (ByVal nShowmessage As Long) As Long ' return point address.
    Private Declare Function Z_Get_DLL_VersionA Lib "WINPPLZ.DLL" (ByVal nShowmessage As Long) As Long
    Private Declare Function Z_Get_Graphic_ColorBMP Lib "WINPPLZ.DLL" (ByVal x As Long, _
            ByVal y As Long, ByVal mem As Long, ByVal filename As String) As Long
    Private Declare Function Z_Get_Graphic_ColorBMPEx Lib "WINPPLZ.DLL" (ByVal x As Long, _
            ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, _
            ByVal rotate As Long, ByVal mem_mode As Long, ByVal id_name As String, _
            ByVal filename As String) As Long
    Private Declare Function Z_Get_Graphic_ColorBMP_HBitmap Lib "WINPPLZ.DLL" (ByVal x As Long, _
            ByVal y As Long, ByVal nWidth As Long, ByVal nHeight As Long, _
            ByVal rotate As Long, ByVal mem_mode As Long, ByVal id_name As String, _
            ByVal hbm As Long) As Long
    Private Declare Function Z_Initial_Setting Lib "WINPPLZ.DLL" (ByVal mode As Long, _
            ByVal Source As String) As Long
    Private Declare Function Z_WriteData Lib "WINPPLZ.DLL" (ByVal IsImmediate As Long, _
            ByVal pbuf As String, ByVal length As Long) As Long
    Private Declare Function Z_ReadData Lib "WINPPLZ.DLL" (ByVal pbuf As String, _
            ByVal length As Long, ByVal dwTimeoutms As Long) As Long
    Private Declare Function Z_Load_Graphic Lib "WINPPLZ.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal memory As Long, ByVal graphicname As String, ByVal hori As Long, _
            ByVal vert As Long) As Long
    Private Declare Function Z_Open_ChineseFont Lib "WINPPLZ.DLL" (ByVal path As String) As Long
    Private Declare Function Z_Print_Form Lib "WINPPLZ.DLL" (ByVal copies As Long, _
            ByVal labset As Long, ByVal mem As Long, ByVal formout As String) As Long
    Private Declare Function Z_Print_Out Lib "WINPPLZ.DLL" (ByVal sets As Long, _
            ByVal copies As Long) As Long
    Private Declare Function Z_Prn_Barcode Lib "WINPPLZ.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal ori As Long, ByVal narrow As Long, ByVal width As Long, ByVal height As Long, _
            ByVal bar_type As Byte, ByVal increase As Long, ByVal data As String, ByVal p1 As Byte, _
            ByVal p2 As Byte, ByVal p3 As Byte, ByVal p4 As Byte, ByVal p5 As Byte) As Long
    Private Declare Function Z_Prn_Text Lib "WINPPLZ.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal ori As Long, ByVal font As Byte, ByVal height As Long, ByVal width As Long, _
            ByVal numeric As Long, ByVal data As String) As Long
    Private Declare Function Z_Prn_Text_Chinese Lib "WINPPLZ.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal fonttype As Long, ByVal id_name As String, ByVal data As String, _
            ByVal mem As Long) As Long
    Private Declare Function Z_Prn_Text_TrueType Lib "WINPPLZ.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal FSize As Long, ByVal FType As String, ByVal Fspin As Long, ByVal FWeight As Long, _
            ByVal FItalic As Long, ByVal FUnline As Long, ByVal FStrikeOut As Long, _
            ByVal id_name As String, ByVal data As String, ByVal mem As Long) As Long
    Private Declare Function Z_Prn_Text_TrueType_W Lib "WINPPLZ.DLL" (ByVal x As Long, _
            ByVal y As Long, ByVal FHeight As Long, ByVal FWidth As Long, ByVal FType As String, _
            ByVal Fspin As Long, ByVal FWeight As Long, ByVal FItalic As Long, ByVal FUnline As Long, _
            ByVal FStrikeOut As Long, ByVal id_name As String, ByVal data As String, _
            ByVal mem As Long) As Long
    Private Declare Sub Z_Clear_Memory Lib "WINPPLZ.DLL" ()
    Private Declare Sub Z_Clear_MemoryEx Lib "WINPPLZ.DLL" (ByVal nMode As Integer)
    Private Declare Function Z_Set_Backfeed Lib "WINPPLZ.DLL" (ByVal nDistance As Long) As Long
    Private Declare Function Z_Set_Darkness Lib "WINPPLZ.DLL" (ByVal darkness As Long) As Long
    Private Declare Function Z_Set_DebugDialog Lib "WINPPLZ.DLL" (ByVal nEnable As Long) As Long
    Private Declare Function Z_Set_Label Lib "WINPPLZ.DLL" (ByVal length As Long) As Long
    Private Declare Function Z_Set_Mode Lib "WINPPLZ.DLL" (ByVal mode As Byte) As Long
    Private Declare Function Z_Set_Origin Lib "WINPPLZ.DLL" (ByVal y As Long) As Long
    Private Declare Function Z_Set_Paper Lib "WINPPLZ.DLL" (ByVal mode As Byte) As Long
    Private Declare Function Z_Set_Prncomport Lib "WINPPLZ.DLL" (ByVal baud As Long, _
            ByVal parity As Long, ByVal data As Long, ByVal stopbit As Long) As Long
    Private Declare Function Z_Set_Prncomport_PC Lib "WINPPLZ.DLL" (ByVal nBaudRate As Long, _
            ByVal nBytesSize As Long, ByVal nParity As Long, ByVal nStopBits As Long, _
            ByVal nDsr As Long, ByVal nCts As Long, ByVal nXonXoff As Long) As Long
    Private Declare Sub Z_Set_Reset Lib "WINPPLZ.DLL" ()
    Private Declare Function Z_Set_Speed Lib "WINPPLZ.DLL" (ByVal speed As Long) As Long
    Private Declare Function Z_Set_TPH Lib "WINPPLZ.DLL" (ByVal mode As Byte) As Long
    Private Declare Function Z_Set_Unit Lib "WINPPLZ.DLL" (ByVal Unit As Byte) As Long
    Private Declare Function Z_Set_Gap Lib "WINPPLZ.DLL" (ByVal nPatern As Long, _
            ByVal nGaplen As Long) As Long
    Private Declare Function Z_Set_ProcessDlg Lib "WINPPLZ.DLL" (ByVal nShow As Long) As Long
    Private Declare Function Z_Set_ErrorDlg Lib "WINPPLZ.DLL" (ByVal nShow As Long) As Long
    Private Declare Function Z_Bar2d_QRCode Lib "WINPPLZ.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal nModel As Long, ByVal nMagni As Long, ByVal nErr_Cor As Long, ByVal nInput As Long, _
            ByVal data As String, ByVal increase As Long) As Long
    Private Declare Function Z_Set_PrintWidth Lib "WINPPLZ.DLL" (ByVal nDotWidth As Long) As Long
    Private Declare Function Z_Print_OutQuality Lib "WINPPLZ.DLL" (ByVal nTotal As Long, _
            ByVal sets As Long, ByVal copies As Long, ByVal nPause As Long) As Long
    Private Declare Function Z_GetUSBBufferLen Lib "WINPPLZ.DLL" () As Long
    Private Declare Function Z_EnumUSB Lib "WINPPLZ.DLL" (ByVal buf As String) As Long
    Private Declare Function Z_CreateUSBPort Lib "WINPPLZ.DLL" (ByVal nPort As Long) As Long
    Private Declare Function Z_CreatePort Lib "WINPPLZ.DLL" (ByVal nPortType As Long, _
            ByVal nPort As Long, ByVal filename As String) As Long
    Private Declare Function Z_Set_Mirror Lib "WINPPLZ.DLL" (ByVal direction As Byte) As Long
    Private Declare Function Z_Bar2d_RSS Lib "WINPPLZ.DLL" (ByVal x As Long, ByVal y As Long, _
            ByVal ori As Byte, ByVal rtype As Long, ByVal mag As Long, ByVal height As Long, _
            ByVal seg As Long, ByVal data1 As String, ByVal data2 As String) As Long
    Private Declare Function Z_GetNetPrinterBufferLen Lib "WINPPLZ.DLL" () As Long
    Private Declare Function Z_EnumNetPrinter Lib "WINPPLZ.DLL" (ByVal buf As String) As Long
    Private Declare Function Z_CreateNetPort Lib "WINPPLZ.DLL" (ByVal nPort As Long) As Long
    'data is buffer address, so can use "ByVal data As Integer".
    Private Declare Function Z_Prn_Text_TrueType_Uni Lib "WINPPLZ.DLL" (ByVal x As Long, _
            ByVal y As Long, ByVal FSize As Long, ByVal FType As String, ByVal Fspin As Long, _
            ByVal FWeight As Long, ByVal FItalic As Long, ByVal FUnline As Long, _
            ByVal FStrikeOut As Long, ByVal id_name As String, ByRef data As Byte, _
            ByVal format As Long, ByVal mem_mode As Long) As Long
    'data is buffer address, so can use "ByVal data As Integer".
    Private Declare Function Z_Prn_Text_TrueType_UniB Lib "WINPPLZ.DLL" (ByVal x As Long, _
            ByVal y As Long, ByVal FSize As Long, ByVal FType As String, ByVal Fspin As Long, _
            ByVal FWeight As Long, ByVal FItalic As Long, ByVal FUnline As Long, _
            ByVal FStrikeOut As Long, ByVal id_name As String, ByRef data As Byte, _
            ByVal format As Long, ByVal mem_mode As Long) As Long
    Private Declare Function Z_GetUSBDeviceInfo Lib "WINPPLZ.DLL" (ByVal nPort As Long, _
            ByVal pDeviceName As String, ByRef pDeviceNameLen As Long, ByVal pDevicePath As String, _
            ByRef pDevicePathLen As Long) As Long
    Private Declare Function Z_Set_EncryptionKey Lib "WINPPLZ.DLL" (ByVal encryptionKey As String) As Long
    Private Declare Function Z_Check_EncryptionKey Lib "WINPPLZ.DLL" (ByVal decodeKey As String, _
            ByVal encryptionKey As String, ByVal dwTimeoutms As Long) As Long
    Private Declare Function Z_Set_CommTimeout Lib "WINPPLZ.DLL" (ByVal ReadTotalTimeoutConstant As Long, _
            ByVal WriteTotalTimeoutConstant As Long) As Long
    Private Declare Function Z_Get_CommTimeout Lib "WINPPLZ.DLL" (ByRef ReadTotalTimeoutConstant As Long, _
            ByRef WriteTotalTimeoutConstant As Long) As Long
    Private Declare Function Z_Set_LabelForSmartPrint Lib "WINPPLZ.DLL" (ByVal lablength As Long, _
            ByVal gaplength As Long) As Long

Private Sub Command1_Click()
        'Test code start
        ' open port.
        Dim nLen As Long
        Dim ret As Long
        Dim sw As Long
        Dim nVersion, nMainVersion, nSubVersion As Long
        Dim pbuf As String
        Dim strmsg As String
        pbuf = Space(128)
        ver = Space(128)

        ' dll version.
        nVersion = Z_Get_DLL_VersionA(0)
        nMainVersion = Int(nVersion / 100)
        nSubVersion = nVersion Mod 100
        
        ' search port.
        nLen = Z_GetUSBBufferLen() + 1
        strmsg = "DLL Ver: " + Str(nMainVersion) + "." + Str(nSubVersion) + vbCrLf  'only sample coding, not smart.
        If nLen > 1 Then
            Dim buf1 As String
            Dim buf2 As String
            Dim len1 As Long
            Dim len2 As Long
            len1 = 128
            len2 = 128
            buf1 = Space(len1)
            buf2 = Space(len2)
            Call Z_EnumUSB(pbuf)
            Call Z_GetUSBDeviceInfo(1, buf1, len1, buf2, len2)
            sw = 1
            If sw Then
                ret = Z_CreatePrn(12, buf2) ' open usb.
            Else
                ret = Z_CreateUSBPort(1) ' must call Z_GetUSBBufferLen() function fisrt.
            End If
            If 0 < ret Then
                strmsg = strmsg + "Open USB fail!"
            Else
                strmsg = strmsg + "Open USB:" + vbCrLf + "Device name: "
                strmsg = strmsg + Left(buf1, len1)
                strmsg = strmsg + vbCrLf + "Device path: "
                strmsg = strmsg + Left(buf2, len2)
                'sw = 2
                If 2 = sw Then
                    'get host status.
                    pbuf = "~HS\r\n"
                    Call Z_WriteData(1, pbuf, 5)   '~HS
                    ret = Z_ReadData(pbuf, 82, 1000)
                End If
            End If
        Else
            Dim lpSA As SECURITY_ATTRIBUTES

            lpSA.nLength = Len(lpSA)
            ret = CreateDirectory(szSavePath, lpSA)
            ret = Z_CreatePrn(0, szSaveFile) ' open file.
            strmsg = strmsg + "Open " + szSaveFile
            If 0 < ret Then
                strmsg = strmsg + " file fail!"
            Else
                strmsg = strmsg + " file succeed!"
            End If
        End If
        MsgBox (strmsg)
        If 0 < ret Then
            Exit Sub
        End If

        ' sample setting.
        Call Z_Set_DebugDialog(1)
        Call Z_Set_Origin(0)
        Call Z_Set_Paper(Asc("Y"))
        Call Z_Set_TPH(Asc("D"))
        Call Z_Set_Unit(Asc("D")) 'dot.
        Call Z_Set_Darkness(8)
        Call Z_Set_Label(203 * 3)
        Call Z_Set_PrintWidth(203 * 4)
        Call Z_Clear_Memory   ' clear memory.
        Call Z_WriteData(0, sznop2, Len(sznop2))
        Call Z_WriteData(1, sznop1, Len(sznop1))
        ' When using standard label, and the printer is Intelli Print mode or Smart Print mode,
        ' When calling this function and giving the correct label information,
        ' the immediate print function will be enabled according to the label length setting.
        Call Z_Set_LabelForSmartPrint(254 * 3, 30) ' label information: length= 3 * 25.4 mm, gap= 3 mm.
        
        'draw box.
        Call Z_Draw_Box(20, 20, 760, 560, 4)
        Call Z_Draw_Line(400, 20, 4, 560)

        'print text, true type text.
        Call Z_Prn_Text(30, 40, 1, Asc("D"), 1, 1, 0, "PPLZ Lib Example")
        Call Z_Prn_Text_TrueType(30, 100, 30, "Arial", 1, 400, 0, 0, 0, "AA", "TrueType Font", 0) 'save in printer.
        Call Z_Prn_Text_TrueType_W(30, 160, 20, 20, "Times New Roman", 1, 400, 0, 0, 0, "AB", "TT_W: 多字元測試", 0)
        
        Dim buff1(128) As Byte
        Dim buff2() As Byte
        Dim i As Long
        buff2 = StrConv("TT_Uni: 多字元測試", vbNarrow) 'Converts UNICODE(wide characters) to single-byte characters.
        For i = LBound(buff2) To UBound(buff2)
            buff1(i) = buff2(i)
        Next i
        buff1(26) = 0 'null.
        buff1(27) = 0
        Call Z_Prn_Text_TrueType_Uni(30, 220, 30, "Times New Roman", 1, 400, 0, 0, 0, "AC", buff1(0), 1, 0) 'UTF-16
        
        buff1(0) = 255 'UTF-16.
        buff1(1) = 254
        buff2 = StrConv("TT_UniB: 多字元測試", vbNarrow) 'Converts UNICODE(wide characters) to single-byte characters.
        For i = LBound(buff2) To UBound(buff2)
            buff1(i + 2) = buff2(i)
        Next i
        buff1(30) = 0 'null.
        buff1(31) = 0
        Call Z_Prn_Text_TrueType_UniB(30, 280, 30, "Times New Roman", 1, 400, 0, 0, 0, "AD", buff1(0), 0, 0) 'Byte Order Mark.

        'barcode.
        Call Z_Prn_Barcode(420, 100, 1, 2, 3, 40, Asc("3"), 1, "1234", Asc("N"), Asc("Y"), Asc("N"), Asc("N"), Asc("N")) 'have a counter.
        Call Z_Bar2d_QRCode(420, 190, 2, 3, 3, 1, "QR CODE", 0)

        'picture.
        Call Z_Get_Graphic_ColorBMP(420, 280, 0, "bb.bmp") ' Color bmp file to ram.
        Call Z_Get_Graphic_ColorBMPEx(420, 330, 200, 150, 2, 0, "bb1", "bb.bmp") ' 180 angle.
        Dim himage As Long
        himage = LoadImage(0, "bb.bmp", IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE)
        Call Z_Get_Graphic_ColorBMP_HBitmap(630, 280, 250, 80, 1, 0, "bb2", himage) ' 90 angle.
        If himage Then
            Call DeleteObject(himage)
        End If

        ' output.
        Call Z_Print_Out(2, 1) ' copy 2.

        ' close port.
        Call Z_ClosePrn
End Sub
